﻿namespace HutongGames.PlayMaker
{
    using System;
    using UnityEngine;

    [Serializable]
    public class FsmObject : NamedVariable
    {
        private System.Type objectType;
        [SerializeField]
        private string typeName;
        [SerializeField]
        private UnityEngine.Object value;

        public FsmObject()
        {
        }

        public FsmObject(FsmObject source) : base(source)
        {
            this.value = source.value;
            this.typeName = source.typeName;
            this.objectType = source.objectType;
        }

        public FsmObject(string name) : base(name)
        {
            this.typeName = typeof(UnityEngine.Object).FullName;
            this.objectType = typeof(UnityEngine.Object);
        }

        public static implicit operator FsmObject(UnityEngine.Object value)
        {
            FsmObject obj3 = new FsmObject();
            obj3.value = value;
            return obj3;
        }

        public override string ToString()
        {
            if (this.value != null)
            {
                return this.value.ToString();
            }
            return "None";
        }

        public System.Type ObjectType
        {
            get
            {
                if (this.objectType == null)
                {
                    if (string.IsNullOrEmpty(this.typeName))
                    {
                        this.typeName = typeof(UnityEngine.Object).FullName;
                    }
                    this.objectType = FsmUtility.GetType(this.typeName);
                }
                return this.objectType;
            }
            set
            {
                this.objectType = value ?? typeof(UnityEngine.Object);
                if (this.value != null)
                {
                    System.Type type = this.value.GetType();
                    if (!type.IsAssignableFrom(this.objectType) && !type.IsSubclassOf(this.objectType))
                    {
                        this.value = null;
                    }
                }
                this.typeName = this.objectType.FullName;
            }
        }

        public string TypeName
        {
            get
            {
                return this.typeName;
            }
        }

        public UnityEngine.Object Value
        {
            get
            {
                return this.value;
            }
            set
            {
                this.value = value;
            }
        }
    }
}

